<?php

session_start();

require_once ("../../../db.php");

if (!isset($_SESSION['uid']) || ($_SESSION['type'] != 'student')) {
    die('Not logged in as an student user');
}

// thei updates the group name
$sql = 'SELECT * FROM groupparticipants WHERE participantid=?';
$sth = $db->prepare($sql);
$sth->execute(array($_SESSION['uid'])); // get the group ID
$group = $sth->fetch();
if ($group) {
    $sql = 'UPDATE projectgroups SET name=? WHERE id=?';    // update the group name
    $sth = $db->prepare($sql);
    $sth->execute(array($_POST['grpname'], $group[0]));
} else {
    echo json_encode(array('error' => 'Du er ikke i noen gruppe'));
}